<%--
  Created by IntelliJ IDEA.
  User: 李涛
  Date: 2020/4/21
  Time: 22:25
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@page isELIgnored="false" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <title>签到</title>
    <link type="text/css" rel="stylesheet" href="static/css/bootstrap.min.css">
    <link type="text/css" rel="stylesheet" href="static/css/style.css">
    <link type="text/css" rel="stylesheet" href="static/css/qiandao_style.css">
</head>
<body>
<div class="container">
    <div class="row">
        <div class="col-xs-12 clearPadding">
            <!--<div class=""><img src="images/qdBanner.jpg" class="img-responsive"></div>-->
          <input type="hidden" id="uid" value="${uid}"><%--隐藏域--%>
            <div class="calendar">
                <div class="calenbox">
                    <div id="calendar"></div>
                </div>
                <div class="text-center">
                    <button class="btn btn-qiandao" onclick="signIn()">马上签到</button>
                </div>
            </div>
            <div class="padding10">
                <div class="font16 pb10 borderb"><strong>连续签到礼包</strong></div>
                <div class="libaolist">
                    <c:forEach items="${activityies}" var="item">
                    <div class="clearfix borderb ptb10">
                        <div class="col-xs-9 clearPadding">
                            <div class="media">
                                <a class="media-left pt3" href="javascript:void(0);">
                                    <img src="static/picture/dou.png" style="width:30px;height:30px;">
                                </a>
                                <div class="media-body">
                                    <div class="">${item.count}天礼包（${item.money}）</div>
                                    <div class="text-muted font12">连续签到${item.count}天即可领取</div>
                                </div>
                            </div>
                        </div>
                        <div class="col-xs-3 clearPadding text-right pt2">
                            <button id="sign${item.count}" class="btn btn-disable"  onclick="lingqu(${item.id})">领取</button>
                        </div>
                    </div>
                    </c:forEach>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="maskbox"></div>
<div class="qdbox">
    <div class="text-center text-green font18"><strong>签到成功！</strong></div>
    <div class="text-center pt10">您已经连续签到&nbsp;<span class="text-green">10</span>&nbsp;天</div>
    <div class="text-center ptb15"><img src="static/picture/gift.png" style="width:125px;margin-left:20px;"></div>
    <div class="text-center"><button class="btn btn-lottery">收到</button></div>
</div>
<script type="text/javascript" src="static/js/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="static/js/calendar.js"></script>
<script>
    function  lingqu(actid){
        var uid=$("#uid").val();
        $.ajax({
            url:"/lqJiFen",
            type:"post",
            data:{uid:uid,actid:actid},
            success:function (data) {
                if (data==-1){
                    alert("积分已经领取过了！再接再厉！");
                }else {
                    alert("恭喜领取成功！");
                   var btn ="#sign"+actid;
                    $(btn).removeClass();
                    $(btn).addClass("btn btn-disable");
                    $(btn).attr("disabled",true);

                }
            }
        });

    }
    function  signIn(){
        var uid=$("#uid").val();
        $.ajax({
            url:"/sign",
            type:"post",
            data:{uid:uid},
            success:function (data) {
                if (data==-1){
                    alert("今天已经签到过了！明天再来哦！");
                }else {
                    alert("恭喜你签到成功！");
                }
            }
        })
    }
    $(".maskbox").click(function(){
        $(".maskbox").fadeOut();
        $(".qdbox").fadeOut();
    });
    $(function(){
        var uid=$("#uid").val();
        //ajax获取日历json数据
        //var signList=[{"signDay":"10"},{"signDay":"11"},{"signDay":"12"},{"signDay":"13"}];
        var signList=[];
        $.ajax({
            url:"/dayList",
            type:"post",
            data:{uid:uid},
            success:function (data) {
                if (data.status==200){
                  var list=data.data;
                  console.log(list);
                  for(var i=0;i<list.length;i++){
                  var obj={"signDay":list[i].day};
                  signList.push(obj);
                  calUtil.init(signList);
                  };
                }else {
                    alert("初始化数据失败！");
                }
            }
        });
        $.ajax({
            url:"/dayCount",
            type:"post",
            data:{uid:uid},
            success:function (data) {
                if (data.status==200){
                    var count=data.data;
                    //var
                    var arr=[
                        <c:forEach items="${activityies}" var="activity">
                        ${activity.count},
                        </c:forEach>
                    ]
                    arr.forEach(function (item,index,arr) {
                        var btn ="#sign"+item;
                         $(btn).removeClass();
                        $(btn).addClass("btn btn-disable");
                        $(btn).attr("disabled",true);
                        if (item<=count){
                            $(btn).removeClass();
                            $(btn).addClass("btn btn-lingqu");
                            $(btn).attr("disabled",false);
                        }
                    })
                }else {
                    alert("初始化数据失败！");
                }
            }
        });
        $.ajax({
            url:"/actlog",
            type:"post",
            data:{uid:uid},
            success:function (data) {
                if (data.status==200){
                    var list=data.data;
                    list.forEach(function (item,index,arr) {
                        var btn ="#sign"+item.count;
                        $(btn).removeClass();
                        $(btn).addClass("btn btn-disable");
                        $(btn).attr("disabled",true);

                    })
                }else {
                    alert("初始化数据失败！");
                }
            }
        });
    });
</script>
</body>
</html>
